#include "kernel/types.h"
#include "kernel/stat.h"
#include "user/user.h"

char *arg[128];

int main(int argc,char *argv[]){
    char buf[128];
    //gets(buf,128);
    for(int i=1;i<argc;i++){
        arg[i-1]=(char*)malloc(strlen(argv[i])+1);
        strcpy(arg[i-1],argv[i]);
        //printf("after--> :<%s>   before--> <%s>\n",arg[i-1],argv[i]);
    }
    while(gets(buf,128)&&strlen(buf)!=0){
        buf[strlen(buf)-1]=0;
        arg[argc-1]=(char*)malloc(strlen(buf)+1);
        strcpy(arg[argc-1],buf);
        arg[argc]=(char*)malloc(1);
        arg[argc]=0;
        for(int i=0;i<=argc;i++){
            //printf("<%s>\n",arg[i]);
        }
        int pid=fork();
        if(pid==0){
            printf("<%s>\n",arg[0]);
            exec(arg[0],arg);
            fprintf(2,"failed\n");
            exit(1);
        } else {
            wait(0);
        }
    }
    free(arg);
    exit(0);
}